/*
Simplified OpenCL Interface
Vlad Levenfeld 2013
*/

#ifndef __VCL_H__
#define __VCL_H__

enum { 
	IO_BUFFER,
	INPUT_BUFFER,
	OUTPUT_BUFFER,
	INTERNAL_BUFFER
};

#include "stdarg.h"
#include "stdio.h"
#include "string.h"
#include "CL/cl.h"

typedef struct CL_meta_struct	CL_meta;
typedef struct kernel_struct	kernel;
typedef struct buffer_struct	buffer;
//////////////////
struct CL_meta_struct {
	cl_platform_id		Plt;
	cl_device_id		Dev;
	cl_context		Ctx;
	cl_command_queue	Cmd;

	kernel* 		K;
	int 			n_K;
};
struct kernel_struct {
	char*			name[128];
	int			args;
	cl_kernel		kernel;
};
struct buffer_struct {
	void*			data;
	cl_mem			vram;
	int			size;
	int			mode;
};

/* 	FUNCTION DIRECTORY 	*/
/*	Engine:		*/
void 	init_CL(void);
void 	load_CL(char* 	_sourcePath);
kernel*	find_CL(char* 	_kernelName);
void 	call_CL(kernel* _K, 
		size_t	_globalWorkItems,
		size_t	_localWorkItems, 
		int 	_setArgs,
		...);
void 	sync_CL(void);	
void	kill_CL(void);
/*	Data:		*/
buffer	initBuffer(int	_size, 
		int 	_type);
void	readBuffer(buffer*);
void	writeBuffer(buffer*);
void	freeBuffer(buffer*);
/*	Utilities:	*/
void 	error_CL(int);
void 	loadSource(char*, char**);

/*	---GLOBAL---		*/
CL_meta CL;

#endif
